package com.jf.mall.service;

import com.jf.mall.dao.FurnitureDAO;
import com.jf.mall.dao.impl.FurnitureImpl;
import com.jf.mall.domain.Furniture;
import com.jf.mall.domain.Page;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-09-26
 * Time:14:59
 */
public class FurnitureService {
    private final FurnitureDAO furnitureDAO = new FurnitureImpl();

    public List<Furniture> getFurniture() {
        return furnitureDAO.queryFurniture();
    }

    public Furniture getFurniture(int id) {
        return furnitureDAO.queryFurnitureById(id);
    }


    public int saveFurniture(Furniture furniture) {
        return furnitureDAO.addFurniture(furniture);
    }

    public int deleteFurniture(int id) {
        return furnitureDAO.deleteFurnitureById(id);
    }

    public int updateFurniture(Furniture furniture) {
        return furnitureDAO.updateFurniture(furniture);
    }
    public Page<Furniture> getFurniturePage(int pageNo, int pageSize) {
        Page<Furniture> page = new Page(pageNo, pageSize);
        page.setElementsCount(furnitureDAO.getFurnitureCount());
        List<Furniture> furniture = furnitureDAO.queryFurnitureByLimit(page.getElementBegin(), page.getPageSize());
        page.setElements(furniture);
        return page;
    }
    public Page<Furniture> getFurniturePageByName(int pageNo, int pageSize, String name) {
        Page<Furniture> page = new Page(pageNo, pageSize);
        page.setElementsCount(furnitureDAO.getFurnitureCountByName(name));
        List<Furniture> furniture = furnitureDAO.queryFurnitureByLimitAndName(page.getElementBegin(), page.getPageSize(), name);
        page.setElements(furniture);
        return page;
    }
}
